
String.prototype.trim=function(){
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

String.prototype.ltrim=function(){
    return this.replace(/(^\s*)/g,"");
}

String.prototype.rtrim=function(){
    return this.replace(/(\s*$)/g,"");
}

String.prototype.replaceAll  = function(s1,s2){
    return this.replace(new RegExp(s1,"gm"),s2);
}

String.prototype.jsonEval = function(){
    return eval("("+this+")");
    // return JSON.parse(this);
}

String.prototype.json = function(){
    return JSON.parse(this);
}

function mouseX(obj){
    var parObj=obj;
    var left=obj.offsetLeft;
    while(parObj=parObj.offsetParent){      left+=parObj.offsetLeft;        }
    return left;
}

function mouseY(obj){
    var parObj=obj;
    var top=obj.offsetTop;
    while(parObj = parObj.offsetParent){        top+=parObj.offsetTop;      }
     return top;
}

function alertMousePos(ta){
    var top,left,oDiv;
    oDiv=ta;
    top=getY(oDiv);
    left=getX(oDiv);

    left=event.clientX-left+document.body.scrollLeft;
    top=event.clientY-top+document.body.scrollTop;
    alert(ta.id+';top='+top+';left='+left);
}

//
function js_strtotime(str_time){
    var new_str = str_time.replace(/:/g,'-');
    new_str = new_str.replace(/ /g,'-');
    var arr = new_str.split("-");
    var datum = new Date(Date.UTC(arr[0],arr[1]-1,arr[2],arr[3]-8,arr[4],arr[5]));
    return strtotime = datum.getTime()/1000;
}

String.prototype.jsDate = function(){
    return js_date(this);
}
function js_date(unixtime) {
    if(isNaN(unixtime)){
        var timestr = new Date();
    }else{
        var timestr = new Date(parseInt(unixtime) * 1000);
    }
    var datetime = timestr;
    return datetime;
}

//+---------------------------------------------------
//| 日期计算
//+---------------------------------------------------
//
String.prototype.time = function() {
    var t = this;
    // console.log('aaa'+t);

    var n = Number(t);
    if (!isNaN(n)){
        //是数值类型
        var d = new Date(parseInt(t) * 1000);
        return d.format();
    }

    
    var new_str = t.replace(/:/g,'-');
        new_str = new_str.replace(/ /g,'-');
    var arr = new_str.split("-");
    var datum = new Date(Date.UTC(arr[0],arr[1]-1,arr[2],arr[3]-8,arr[4],arr[5]));
    return strtotime = datum.getTime()/1000;
}

Number.prototype.time = function(argu) {
    var t = this;
    var d = new Date(parseInt(t) * 1000);
    return d.format(argu);
}

Date.prototype.time = function() {
    var t = this;
    return t.format().time();
}



Date.prototype.add = function(Number) {
    var t = this;
    var a = new Date().format().time();
    a += Number;
    return new Date(parseInt(a) * 1000);
}

//日期格式化
Date.prototype.format = function(fmt){
    if(typeof fmt == 'undefined'){
        fmt = 'yyyy-MM-dd hh:mm:ss';
    }
  var o = {   
    "M+" : this.getMonth()+1,                 //月份   
    "d+" : this.getDate(),                    //日   
    "h+" : this.getHours(),                   //小时   
    "m+" : this.getMinutes(),                 //分   
    "s+" : this.getSeconds(),                 //秒   
    "q+" : Math.floor((this.getMonth()+3)/3), //季度   
    "S"  : this.getMilliseconds()             //毫秒   
  };   
  if(/(y+)/.test(fmt))   
    fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));   
  for(var k in o)   
    if(new RegExp("("+ k +")").test(fmt))   
  fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));   
  return fmt;   
}
